package cn.pugle.datasketches;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

/**
 * @author tzp
 * @since 2019/7/3
 */
public class DataGen {
    public static void main(String[] args) throws IOException {
        genGaussian("/Users/tzp/Documents/private/cnm/CodeAccumulate/target/score", 1000, 500, 100);
    }

    /**
     * https://stackoverflow.com/a/31754210/5142886
     */
    public static void genGaussian(String file, int num, double mean, double standardDeviation) throws IOException {
        Random r = new Random();
        BufferedWriter bw = new BufferedWriter(
                new FileWriter(file));
        for (int i = 0; i < num; i++) {
            double value = r.nextGaussian() //这个函数返回平均数是0, 标准差是1的正态分布的随机值
                    * standardDeviation + mean;
            bw.write(String.format("%.2f", value));
            bw.newLine();
        }
        bw.flush();
        bw.close();
    }
}
